package com.xiefengf.elasticsearch.jd.controller;

import com.xiefengf.elasticsearch.jd.model.Content;
import com.xiefengf.elasticsearch.jd.service.ContentService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author xiefengf
 * @version 1.0
 * @date 2024/4/6 23:13
 * <p>
 * 请求编写
 */
@RestController
public class ContentController {

    @Resource
    private ContentService contentService;

    /**
     * 解析JD网页数据同时放入ES索引中 - http://localhost:9991/es/parseContent/vue
     *
     * @param keyword
     * @return
     */
    @GetMapping("/parseContent/{keyword}")
    public Boolean parseContent(@PathVariable("keyword") String keyword) {
        return contentService.parseContent(keyword);
    }

    /**
     * 条件分页搜索数据 - http://localhost:9991/es/parseContent/title/vue.js/0/5
     * @param field
     * @param value
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/parseContent/{field}/{value}/{pageNo}/{pageSize}")
    public List<Content> searchPage(@PathVariable("field") String field
                                    , @PathVariable("value") String value
                                    , @PathVariable("pageNo") int pageNo
                                    , @PathVariable("pageSize") int pageSize) {
        return contentService.searchPage(field,value,pageNo,pageSize);
    }

}
